package com.neuronbit.businessflow.intellij.model;

import com.neuronbit.businessflow.intellij.model.annotation.HiddenProperty;
import com.neuronbit.businessflow.intellij.model.annotation.ReadonlyProperty;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Objects;

/**
 * The type Node.
 */
@Getter
public abstract class Node implements Serializable {
    private String id;
    @Setter
    private String name;
    private NodeType nodeType;
    @Setter
    private String description;

    /**
     * Instantiates a new Node.
     *
     * @param id       the id
     * @param name     the name
     * @param nodeType the node type
     */
    public Node(String id, String name, NodeType nodeType) {
        this.id = id;
        this.name = name;
        this.nodeType = nodeType;
    }

    /**
     * Sets id.
     *
     * @param id the id
     */
    @HiddenProperty
    public void setId(String id) {
        this.id = id;
    }

    /**
     * Gets id.
     *
     * @return the id
     */
    public String getId() {
        return id;
    }

    @Override
    public String toString() {
        if (StringUtils.isNotBlank(description)) {
            return description + "\n" + name;
        } else {
            return name;
        }
    }

    /**
     * Gets capitalize name.
     *
     * @return the capitalize name
     */
    public String getCapitalizeName() {
        return StringUtils.capitalize(name);
    }

    /**
     * Gets un capitalize name.
     *
     * @return the un capitalize name
     */
    public String getUnCapitalizeName() {
        return StringUtils.uncapitalize(name);
    }

    /**
     * Sets node type.
     *
     * @param nodeType the node type
     */
    @ReadonlyProperty
    public void setNodeType(NodeType nodeType) {
        this.nodeType = nodeType;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Node node = (Node) o;
        return Objects.equals(id, node.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }
}
